package org.anupta.game.main;

import org.anupta.game.server.game.GameServer;
import org.anupta.game.server.inter.InterServer;
import org.anupta.game.utils.others.EnumsInfo.State;
import org.anupta.game.utils.others.ErrorLogger;
import org.anupta.game.utils.others.Config;
import org.anupta.game.utils.others.OutLogger;
import org.anupta.game.utils.others.TimerThread;
import org.anupta.game.utils.sql.Database;
import org.anupta.game.utils.sql.Sql;

public class Main {
	public static ErrorLogger err = null;
    public static OutLogger out = null;
    public static InterServer inter = new InterServer();
    public static GameServer game = new GameServer();
    
	public static void main(String[] args) {
		Runtime.getRuntime().addShutdownHook(new Thread()
		{
			public void run()
			{
				close();
			}});
		Config.ID = Byte.parseByte(args[0]);
		out = new OutLogger();
		err = new ErrorLogger();
		Config.readConfig("config.xml");
		long time = System.nanoTime();
		Database.getDatabase(Config.DRIVER, Config.LOGIN[0], Config.LOGIN[1], Config.LOGIN[2]);
		Database.getDatabase(Config.DRIVER, Config.LOGIN_GAME[0], Config.LOGIN_GAME[1], Config.LOGIN_GAME[2]);
        Sql.setAllDAO();
        game.bind(Config.GAME_PORT);
        Config.STATE = State.ONLINE;
        inter.bind(Config.INTER_PORT);
        new TimerThread();
        out.println("Started in : " + (System.nanoTime() - time) + " nanoseconds");
	}
	
	public static void close(){
        err.close();
        out.close();
    }
}
